package com.orangeforms.common.flow.listener;

import java.util.Map;

import com.coalmine.activiti.flow.constant.CmFlowConstant;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

import com.coalmine.activiti.common.flow.constant.FlowConstant;

import lombok.extern.slf4j.Slf4j;

/**
 * 业务审核用户动态设置
 *
 * @author zhaom
 */
@Slf4j
public class BusinessApprovalUserListener implements TaskListener {

    @Override
    public void notify(DelegateTask delegateTask) {
        Map<String, Object> variables = delegateTask.getVariables();
        //会签
        if (variables.get(FlowConstant.MULTI_ASSIGNEE_LIST_VAR) != null) {
        	//delegateTask.setAssignee(String.valueOf(variables.get(FlowConstant.MULTI_ASSIGNEE_LIST_VAR).toString()));
        	return;
		}
        // 设置审批人
        if (variables.get(CmFlowConstant.GROUP_TYPE_BUSINESS_APPROVAL_USER_VAR) == null) {
            delegateTask.setAssignee(variables.get(FlowConstant.PROC_INSTANCE_START_USER_NAME_VAR).toString());
        } else {
            String nextNodeApprover = (String) variables.get(CmFlowConstant.NEXT_NODE_APPROVER);
            delegateTask.setAssignee(nextNodeApprover);
        }
    }
}